package com.pcj.blog.web;
/**
 * @param
 * @author pcj
 * @date 2022/1/7 9:22
 * @return
 */

import com.pcj.blog.po.Type;
import com.pcj.blog.service.BlogService;
import com.pcj.blog.service.TypeService;
import com.pcj.blog.vo.BlogVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 *
 * @className TypeController
 * @author pengcj
 * @date 2022/1/7 9:22
 */
@Controller
public class TypeShowController {
    @Autowired
    private TypeService typeService;
    @Autowired
    private BlogService blogService;
    @GetMapping("/types/{id}")
    public String types(@PageableDefault(size = 1,sort = "updateTime",direction = Sort.Direction.DESC) Pageable pageable, Model model, @PathVariable Long id){
        List<Type> types=typeService.listType();
        if(id==-1){//从导航栏进入
            id=types.get(0).getId();
        }
        BlogVo blogVo=new BlogVo();
        blogVo.setId(id);//type 类型id
        model.addAttribute("types",types);
        model.addAttribute("page",blogService.listBlog(pageable,blogVo));
        model.addAttribute("acctiveTypeId",id);
        return "types";
    }
}
